﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <title>编辑内容</title>
    <link rel="stylesheet" href="~/lib/element-ui/theme-chalk/index.css" />
    <link rel="stylesheet" href="~/admin/css/default/style.css" />
    <!--quill editer-->
    <link rel="stylesheet" href="~/lib/quill/quill.core.css" />
    <link rel="stylesheet" href="~/lib/quill/quill.snow.css" />
    <link rel="stylesheet" href="~/lib/quill/quill.bubble.css" />
    <link rel="stylesheet" href="~/lib/quill/quill-zh-cn.css" />
</head>

<body class="mainbody">
    <div id="app" v-cloak>
        <div class="location">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>
                    <i class="el-icon-s-home"></i>
                    管理中心
                </el-breadcrumb-item>
                <el-breadcrumb-item>首页</el-breadcrumb-item>
                <el-breadcrumb-item>内容管理</el-breadcrumb-item>
                <el-breadcrumb-item>编辑内容</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="content-box">
            <el-form ref="editForm" :model="model" :rules="rules" :label-position="labelPosition" label-width="120px">
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane label="基本信息" name="info">
                        <div class="tab-content">
                            <el-form-item label="选择类别">
                                <dt-dropdown-check v-model="form.categoryCheckedNodes"
                                                   :data="form.categoryList"
                                                   :checked="form.categoryCheckedKeys">
                                </dt-dropdown-check>

                            </el-form-item>
                            <el-form-item label="状态">
                                <el-radio-group v-model="model.status">
                                    <el-radio-button label="0">正常</el-radio-button>
                                    <el-radio-button label="1">待审</el-radio-button>
                                    <el-radio-button label="2">已删</el-radio-button>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item v-if="articleLabel.length>0" label="标签属性">
                                <el-checkbox-group v-model="labelRelations">
                                    <el-checkbox-button v-for="label in articleLabel" :label="label.id" :key="label.id">{{label.title}}</el-checkbox-button>
                                </el-checkbox-group>
                            </el-form-item>
                            <el-form-item prop="title" label="标题">
                                <el-input v-model="model.title" placeholder="" show-word-limit maxlength="512"></el-input>
                            </el-form-item>
                            <el-form-item prop="imgUrl" label="封面图片">
                                <dt-upload-text v-model="model.imgUrl"
                                                placeholder="请上传封面图片"
                                                width="20%"
                                                height="10%"
                                                fit="cover"
                                                :size="sysconfig.imgSize"
                                                exts="jpg,jpeg,png,gif"
                                                action="/upload">
                                </dt-upload-text>
                            </el-form-item>
                            <el-form-item prop="sortId" label="排序数字" :rules="rules.number">
                                <el-input v-model="model.sortId" placeholder="数字越小越排前"></el-input>
                            </el-form-item>
                            <el-form-item prop="click" label="浏览次数" :rules="rules.number">
                                <el-input v-model="model.click" placeholder=""></el-input>
                            </el-form-item>
                            <el-form-item prop="source" label="来源">
                                <el-input v-model="model.source" placeholder="文章的来源地址"></el-input>
                            </el-form-item>
                            <el-form-item prop="author" label="作者">
                                <el-input v-model="model.author" placeholder="文章作者"></el-input>
                            </el-form-item>
                            <el-form-item v-if="channelModel.isAttach==1" label="附件上传">
                                <dt-upload-attach v-model="form.attachList" :size="sysconfig.attachSize" :exts="sysconfig.fileExtension"></dt-upload-attach>
                            </el-form-item>
                            <el-form-item v-if="channelModel.isAlbum==1" label="相册上传">
                                <dt-upload-album v-model="form.albumList" size="2048"></dt-upload-album>
                            </el-form-item>
                            <el-form-item label="发布时间">
                                <el-date-picker v-model="model.addTime"
                                                type="datetime"
                                                value-format="yyyy-MM-dd HH:mm:ss"
                                                placeholder="发布时间">
                                </el-date-picker>
                            </el-form-item>
                            <el-form-item label="允许评论">
                                <el-switch :active-value="1" :inactive-value="0" v-model="model.isComment"></el-switch>
                            </el-form-item>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="详细描述" name="details">
                        <div class="tab-content">
                            <el-form-item prop="callIndex" label="调用别名">
                                <el-input v-model="model.callIndex" maxlength="128" placeholder="非必填，单页可做为别名"></el-input>
                            </el-form-item>
                            <el-form-item prop="linkUrl" label="外部链接">
                                <el-input type="text" v-model="model.linkUrl"></el-input>
                            </el-form-item>
                            <el-form-item prop="zhaiyao" label="内容摘要">
                                <el-input type="textarea" :row="3" v-model="model.zhaiyao" show-word-limit maxlength="255"></el-input>
                            </el-form-item>
                            <el-form-item prop="content" label="内容介绍">
                                <dt-editor v-model="model.content" placeholder="请输入内容介绍"></dt-editor>
                            </el-form-item>
                        </div>
                    </el-tab-pane>
                    <template v-if="model.articleFields.length>0">
                        <el-tab-pane label="扩展内容" name="fields">
                            <div class="tab-content">
                                <template v-for="(field,index) in model.articleFields">
                                    <!--单行文本框-->
                                    <el-form-item v-if="field.controlType=='input'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <el-input v-if="field.isPassword==0" v-model="field.fieldValue" :placeholder="field.validTipMsg"></el-input>
                                        <el-input v-else v-model="field.fieldValue" :placeholder="field.validTipMsg" show-password></el-input>
                                    </el-form-item>
                                    <!--多行文本框-->
                                    <el-form-item v-else-if="field.controlType=='textarea'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <el-input type="textarea" v-model="field.fieldValue" :placeholder="field.validTipMsg"></el-input>
                                    </el-form-item>
                                    <!--编辑器-->
                                    <el-form-item v-else-if="field.controlType=='editor'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <div style="min-height:230px;">
                                            <dt-editor v-if="field.editorType==0" v-model="field.fieldValue" placeholder="field.validTipMsg"></dt-editor>
                                            <dt-editor mini v-if="field.editorType==1" v-model="field.fieldValue" placeholder="field.validTipMsg"></dt-editor>
                                        </div>
                                    </el-form-item>
                                    <!--图片上传-->
                                    <el-form-item v-else-if="field.controlType=='images'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <dt-upload-text v-model="field.fieldValue"
                                                        :placeholder="field.validTipMsg"
                                                        exts="jpg,jpeg,png,gif"
                                                        :size="sysconfig.imgSize"
                                                        action="/upload">
                                        </dt-upload-text>
                                    </el-form-item>
                                    <!--视频上传-->
                                    <el-form-item v-else-if="field.controlType=='video'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <dt-upload-text v-model="field.fieldValue"
                                                        :placeholder="field.validTipMsg"
                                                        :exts="sysconfig.videoExtension"
                                                        :size="sysconfig.videoSize"
                                                        action="/upload"></dt-upload-text>
                                    </el-form-item>
                                    <!--日期时间-->
                                    <el-form-item v-else-if="field.controlType=='datetime'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <el-date-picker v-model="field.fieldValue" value-format="yyyy-MM-dd HH:mm:ss" :placeholder="field.validTipMsg" type="datetime">
                                        </el-date-picker>
                                    </el-form-item>
                                    <!--多项单选-->
                                    <el-form-item v-else-if="field.controlType=='radio'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <el-radio-group v-model="field.fieldValue">
                                            <el-radio v-for="(item,index) in field.options" :label="item[1]" :key="item[1]">{{item[0]}}</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                    <!--多项多选-->
                                    <el-form-item v-else-if="field.controlType=='checkbox'" :prop="'articleFields.'+index+'.fieldValue'" :rules="fieldRules[field.name]" :label="field.title">
                                        <el-checkbox-group v-model="field.fieldValue">
                                            <el-checkbox v-for="(item,index) in field.options" :label="item[1]" :key="item[1]">{{item[0]}}</el-checkbox>
                                        </el-checkbox-group>
                                    </el-form-item>
                                </template>
                            </div>
                        </el-tab-pane>
                    </template>
                    <el-tab-pane label="SEO选项" name="seo">
                        <div class="tab-content">
                            <el-form-item prop="seoTitle" label="SEO标题">
                                <el-input type="text" v-model="model.seoTitle"></el-input>
                            </el-form-item>
                            <el-form-item prop="seoKeyword" label="SEO关健字">
                                <el-input type="text" v-model="model.seoKeyword"></el-input>
                            </el-form-item>
                            <el-form-item prop="seoDescription" label="SEO描述">
                                <el-input type="textarea" :row="3" v-model="model.seoDescription" show-word-limit maxlength="512"></el-input>
                            </el-form-item>
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </el-form>
        </div>

        <div class="footer-box">
            <div class="footer-btn">
                <el-button type="primary" @@click="submitForm">确认保存</el-button>
                <el-button plain @@click="resetForm">返回上一页</el-button>
            </div>
        </div>
    </div>

    <script src="~/lib/vue/vue.js"></script>
    <script src="~/lib/element-ui/index.js"></script>
    <script src="~/lib/axios/axios.min.js"></script>
    <script src="~/lib/babel-polyfill/polyfill.min.js"></script>
    <script src="~/admin/js/axios.config.js"></script>
    <script src="~/admin/js/tree.component.js"></script>
    <script src="~/admin/js/upload.component.js"></script>
    <!--quill editer-->
    <script src="~/lib/quill/quill.min.js"></script>
    <script src="~/lib/quill/vue-quill-editor.js"></script>
    <script src="~/lib/quill/image-resize.min.js"></script>
    <script src="~/admin/js/editor.component.js"></script>
    <script>
        //初始化VUE
        var ve = new Vue({
            el: '#app',
            data: {
                activeName: 'info',//当前选项卡
                labelPosition: 'right',//表单对齐方式
                dialogFieldIndex: -1,//正在编辑的索引号
                dialogFieldVisible: false,//编辑对话框
                form: {
                    categoryList: [],//类别列表
                    categoryCheckedKeys: [],//初始化选中健，修改赋值
                    categoryCheckedNodes: [],//当前选中类别节点,保存取值
                    albumList: [],//相册列表,保存取值
                    attachList: [],
                },
                organList: [],
                model: {
                    articleFields: [],
                    articleCategoryRelations: [],
                    articleLabelRelations: [],
                    articleAlbums: [],
                    articleAttachs: [],
                    channelId: 0,
                    callIndex: '',
                    title: '',
                    source: '',
                    author: '',
                    linkUrl: '',
                    imgUrl: '',
                    seoTitle: '',
                    seoKeyword: '',
                    seoDescription: '',
                    zhaiyao: '',
                    content: '',
                    sortId: 99,
                    addTime: '',
                    click: 100,
                    status: 0,
                    isComment:0,
                },
                rules: {
                    articleCategoryRelations: [
                        { type: 'array', required: true, message: '请选择栏目类别', trigger: 'blur' },
                    ],
                    title: [
                        { required: true, message: '标题不可为空', trigger: 'blur' },
                        { max: 512, message: '标题不可超出512字符', trigger: 'blur' }
                    ],
                    source: [
                        { max: 128, message: '来源不可超出128字符', trigger: 'blur' }
                    ],
                    author: [
                        { max: 128, message: '作者不可超出128字符', trigger: 'blur' }
                    ],
                    callIndex: [
                        { max: 128, message: '别名不可超出128字符', trigger: 'blur' }
                    ],
                    linkUrl: [
                        { max: 512, message: '外部链接不可超出512字符', trigger: 'blur' }
                    ],
                    imgUrl: [
                        { max: 512, message: '图片地址不可超出512字符', trigger: 'blur' }
                    ],
                    seoTitle: [
                        { max: 512, message: 'SEO标题不可超出512字符', trigger: 'blur' }
                    ],
                    seoKeyword: [
                        { max: 512, message: 'SEO关健字不可超出512字符', trigger: 'blur' }
                    ],
                    seoDescription: [
                        { max: 512, message: 'SEO描述不可超出512字符', trigger: 'blur' }
                    ],
                    zhaiyao: [
                        { max: 255, message: '内容摘要不可超出255字符', trigger: 'blur' }
                    ],
                    number: [
                        { pattern: /^\d+$/, message: '请输入正确的数字', trigger: 'blur' },
                    ],
                },
                fieldRules: {},
                channelModel: {},
                sysconfig: {},
                articleLabel: [],
                labelRelations: [],//暂存标签关系
                copyId: 0,
            },
            methods: {
                //初始化数据
                initData: function () {
                    let _this = this; //当前页面
                    let id = GetQueryValue("id"); //获取ID
                    let copyId = GetQueryValue("copyId"); //复制ID
                    _this.copyId = copyId;
                    if (copyId) {
                        id = copyId;
                    }

                    _this.model.channelId = GetQueryValue("channelId"); //获取channelId
                    const loading = _this.$loading({ body: true, lock: true });
                    //获取系统信息
                    new Promise(resolve => {
                        AxiosAjax({
                            url: `/client/setting/sysconfig`,
                            loading: false,
                            success: function (res) {
                                _this.sysconfig = res.data;
                                resolve('ok');
                            }
                        });
                    }).then(val => {
                        //获取可用的标签
                        return new Promise(resolve => {
                            AxiosAjax({
                                url: `/article/label/view/${_this.model.channelId}/1000?status=0`,
                                loading: false,
                                success: function (res) {
                                    _this.articleLabel = res.data;
                                    resolve('ok');
                                }
                            });
                        });
                    }).then(val => {
                        //获取频道信息
                        return new Promise(resolve => {
                            AxiosAjax({
                                url: `/channel/${_this.model.channelId}`,
                                loading: false,
                                success: function (res) {
                                    _this.channelModel = res.data;
                                    resolve('ok');
                                }
                            });
                        })
                    }).then(val => {
                        //获取分类列表
                        return new Promise(resolve => {
                            let sendUrl = `/article/category/${_this.model.channelId}`;
                            //加载父级列表
                            AxiosAjax({
                                url: sendUrl,
                                loading: false,
                                success: function (res) {
                                    _this.form.categoryList = res.data
                                    resolve('ok');
                                }
                            });
                        })
                    }).then(val => {
                        //获取文章信息
                        return new Promise(resolve => {
                            if (id) {
                                AxiosAjax({
                                    url: `/article/${_this.model.channelId}/${id}`,
                                    loading: false,
                                    success: function (res) {
                                        //赋值给model
                                        Object.keys(_this.model).forEach(key => { _this.model[key] = res.data[key] });
                                        console.log(res.data);
                                        //如果是复制
                                        if (_this.copyId) {
                                            _this.model.id = 0;
                                            id = 0;
                                        } else {
                                            _this.model.id = id;
                                        }

                                        //将标签设为选中
                                        if (_this.model.articleLabelRelations.length > 0) {
                                            _this.model.articleLabelRelations.map(function (val) {
                                                _this.labelRelations.push(val.labelId);
                                            });
                                        }

                                        //给类别设置选中赋值
                                        if (_this.model.articleCategoryRelations) {
                                            let categoryIds = [];
                                            _this.model.articleCategoryRelations.map(item => {
                                                categoryIds.push(item.categoryId);
                                            });
                                            _this.form.categoryCheckedKeys = categoryIds;
                                        }
                                        
                                        resolve('ok');
                                    }
                                });
                            } else {
                                resolve('ok');
                            }
                        })
                    }).then(val => {
                        //初始化扩展字段
                        _this.initArticleFields();
                        //相册赋值
                        if (_this.model.articleAlbums) {
                            _this.model.articleAlbums.map(function (item) {
                                item.url = item.thumbPath;
                                _this.form.albumList.push(item);
                            })
                        }
                        //附件赋值
                        if (_this.model.articleAttachs) {
                            _this.model.articleAttachs.map(function (item) {
                                item.fileName = item.fileName;
                                item.articleId = item.articleId;
                                item.filePath = item.filePath;
                                item.fileSize = item.fileSize;
                                item.fileExt = item.fileExt;
                                item.downCount = item.downCount;
                                _this.form.attachList.push(item);
                            })
                        }
                        loading.close();
                    });
                },
                //表单提交
                submitForm: function () {
                    let _this = this; //当前页面
                    //多个表单验证
                    const f1 = new Promise((resolve, reject) => {
                        _this.$refs['editForm'].validate((valid) => {
                            if (valid) resolve()
                        });
                    });
                    Promise.all([f1]).then(() => {
                        //检查及组合参数
                        if (_this.form.categoryCheckedNodes.length === 0) {
                            _this.$message({ type: 'warning', message: '错误提示：请选择文章类别' });
                            return false;
                        }
                        //格式化相册数据去除没有上传成功的数据
                        _this.formatAlbum();
                        //格式化附件数据去除没有上传成功的数据
                        _this.formatAttach();
                        let model = JSON.parse(JSON.stringify(_this.model));
                        //处理扩展字段
                        model.articleFields.forEach(function (val, index) {
                            if (Array.isArray(val.fieldValue)) {
                                val.fieldValue = val.fieldValue.join(',');
                            }
                            //如果是复制
                            if (_this.copyId) {
                                val.id = 0;
                            }
                        });
                        //分类取值
                        let categoryRelations = [];
                        _this.form.categoryCheckedNodes.map(function (item) {
                            let modelt = {
                                id: 0,
                                articleId: model.id,
                                categoryId: item.id
                            }
                            //遍历Model已有值，防止ID丢失
                            model.articleCategoryRelations.map(function (v) {
                                //复制的时候
                                if (_this.copyId) {
                                    if (modelt.categoryId === v.categoryId) {
                                        modelt.id = 0;
                                    }
                                } else {
                                    if (modelt.categoryId === v.categoryId) {
                                        modelt.id = v.id;
                                    }
                                }
                                
                            });
                            categoryRelations.push(modelt);
                        });
                        model.articleCategoryRelations = categoryRelations;
                        //相册取值
                        let albumList = [];
                        _this.form.albumList.map(function (item) {
                            //复制的时候
                            if (_this.copyId) {
                                albumList.push({
                                    id: 0,
                                    articleId: _this.model.id,
                                    thumbPath: item.thumbPath,
                                    originalPath: item.originalPath,
                                    remark: item.remark
                                });
                            } else {
                                albumList.push({
                                    id: item.id,
                                    articleId: _this.model.id,
                                    thumbPath: item.thumbPath,
                                    originalPath: item.originalPath,
                                    remark: item.remark
                                });
                            }
                            
                        });
                        model.articleAlbums = albumList;
                        //附件取值
                        let attachList = [];
                        _this.form.attachList.map(function (item) {
                            //复制的时候
                            if (_this.copyId) {
                                attachList.push({
                                    id: 0,
                                    fileName: item.fileName,
                                    articleId: _this.model.id,
                                    filePath: item.filePath,
                                    fileSize: item.fileSize,
                                    fileExt: item.fileExt,
                                    downCount: item.downCount,
                                });
                            } else {
                                attachList.push({
                                    id: item.id,
                                    fileName: item.fileName,
                                    articleId: _this.model.id,
                                    filePath: item.filePath,
                                    fileSize: item.fileSize,
                                    fileExt: item.fileExt,
                                    downCount: item.downCount,
                                });
                            }
                            
                        });
                        model.articleAttachs = attachList;
                        //处理标签ID的问题
                        if (_this.labelRelations.length > 0) {
                            let labelRelations = [];
                            _this.labelRelations.forEach(function (val, i) {
                                getLabel(val);
                            });
                            function getLabel(val) {
                                let obj = { articleId: _this.model.id, labelId: val, id: 0 };
                                model.articleLabelRelations.forEach(function (v) {
                                    if (val == v.labelId) {
                                        //不是复制的时候
                                        if (!_this.copyId) {
                                            obj.id = v.id;
                                        }
                                        
                                    }
                                });
                                labelRelations.push(obj);
                            }
                            model.articleLabelRelations = labelRelations;
                        }
                        console.log(model);
                        //提交表单,Id大于0则修改，否则添加
                        if (_this.model.id > 0) {
                            AxiosAjax({
                                method: 'put',
                                url: `/article/${_this.model.channelId}/${_this.model.id}`,
                                data: model,
                                loading: true,
                                successMsg: '修改文章成功',
                                success: function (res) {
                                    //可以做跳转到列表页
                                    _this.linkUrl('articlelist');
                                }
                            });
                        } else {
                            AxiosAjax({
                                method: 'post',
                                url: `/article/${_this.model.channelId}`,
                                data: model,
                                loading: true,
                                successMsg: '新增文章成功',
                                success: function (res) {
                                    //重置表单
                                    _this.$refs['editForm'].resetFields();
                                }
                            });
                        }
                    })
                },
                //初始化扩展字段
                initArticleFields() {
                    let _this = this;
                    //重置验证规则
                    _this.fieldRules = {};

                    _this.channelModel.fields.forEach(function (val, i) {
                        //编辑的时候触发
                        if (_this.model.id > 0 || _this.copyId>0) {
                            //获得扩展字段值
                            let obj = getArticleFieldsValue(val.name);
                            //构建ArticleFields属性
                            val.fieldName = val.name;
                            val.fieldId = val.id;
                            val.id = obj.id;
                            val.articleId = _this.model.id;
                            //如果值存在，将值替换默认值
                            if (obj.value) {
                                //如果是数组
                                if (Array.isArray(val.fieldValue)) {
                                    val.fieldValue = obj.value.split(',');
                                } else {
                                    val.fieldValue = obj.value;
                                }
                            } else {
                                if (Array.isArray(val.fieldValue)) {
                                    val.fieldValue = [];
                                } else {
                                    val.fieldValue = '';
                                }
                            }
                        } else {
                            //构建ArticleFields属性
                            val.fieldName = val.name;
                            val.fieldId = val.id;
                            val.articleId = 0;
                        }
                        //生成验证规则
                        getRules(val);
                    });
                    _this.model.articleFields = _this.channelModel.fields;
                    //获得扩展字段值
                    function getArticleFieldsValue(name) {
                        let obj = { value: '', id: 0 };
                        //console.log(_this.model.articleFields);
                        if (_this.model.articleFields.length > 0) {
                            _this.model.articleFields.forEach(function (val, index) {
                                if (val.fieldName == name) {
                                    obj = { value: val.fieldValue, id: val.id };
                                    //console.log(obj);
                                }
                            });
                        }
                        return obj;
                    };
                    //生成验证规则
                    function getRules(obj) {
                        let item = [];
                        //blur验证的控件
                        if (obj.controlType == 'input' ||
                            obj.controlType == 'textarea' ||
                            obj.controlType == 'editor' ||
                            obj.controlType == 'images' ||
                            obj.controlType == 'video' ||
                            obj.controlType == 'datetime'
                        ) {
                            //必填项
                            if (obj.isRequired == 1) {
                                let eleRule = { required: true, message: obj.title + '不能为空', trigger: 'blur' };
                                item.push(eleRule);
                            }
                            //检查正则是否为null
                            if (!(!obj.validPattern && typeof (obj.validPattern) != 'undefined' && obj.validPattern != 0)) {
                                //不为空，将字符串转成正则表达式
                                let eleRule = { pattern: eval(obj.validPattern), message: obj.validErrorMsg, trigger: 'blur' }
                                item.push(eleRule);
                            }

                        } else if (obj.controlType == 'radio' ||
                            obj.controlType == 'checkbox') {
                            //change验证的控件
                            //必填项
                            if (obj.isRequired == 1) {
                                let eleRule = { required: true, message: obj.title + '不能为空', trigger: 'change' };
                                item.push(eleRule);
                            }
                            //检查正则是否为null
                            if (!(!obj.validPattern && typeof (obj.validPattern) != 'undefined' && obj.validPattern != 0)) {
                                //不为空，将字符串转成正则表达式
                                let eleRule = { pattern: eval(obj.validPattern), message: obj.validErrorMsg, trigger: 'change' }
                                item.push(eleRule);
                            }
                        }
                        let name = obj.name;
                        _this.fieldRules[name] = item;
                    };
                },
                //跳转链接
                linkUrl: function (url) {
                    var _this = this;
                    if (url.indexOf('?') >= 0) {
                        url = url + '&channelId=' + _this.model.channelId;
                    } else {
                        url = url + '?channelId=' + _this.model.channelId;
                    }
                    window.location.href = url;
                },
                //返回上一页
                resetForm() {
                    window.history.back(-1);
                },
                //关闭弹窗及重置字段
                resetField() {
                    this.dialogFieldIndex = -1
                    this.$refs['fieldForm'].resetFields();
                },


                //格式化相册数据
                formatAlbum() {
                    let _this = this;
                    let albumsArr = [];
                    if (_this.model.articleAlbums) {
                        let albums = _this.model.articleAlbums;
                        for (let i = 0; i < albums.length; i++) {
                            if (albums[i].status === 'success') {
                                albumsArr.push(albums[i]);
                            }
                        }
                        _this.model.articleAlbums = albumsArr;
                    }
                },
                //格式化附件数据
                formatAttach() {
                    let _this = this;
                    let attachArr = [];
                    if (_this.model.articleAttachs) {
                        let attachs = _this.model.articleAttachs;
                        for (let i = 0; i < attachs.length; i++) {
                            if (attachs[i].status === 'success') {
                                attachArr.push(attachs[i]);
                            }
                        }
                        _this.model.articleAttachs = attachArr;
                    }
                },
            },
            created: function () {
            },
            mounted: function () {
                //初始化数据
                this.initData();
            },
        })
    </script>
</body>
</html>
